//package com.tkmybatis.hfy.aop;
//
//import java.lang.reflect.Method;
//import java.util.List;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import com.alibaba.fastjson.JSON;
//import cn.cmcc.es.common.UserUtils;
//import cn.cmcc.es.exception.ErrorType;
//import cn.cmcc.es.exception.EsException;
//import cn.cmcc.es.feign.system.service.UserService;
//import cn.cmcc.es.hfy.annotation.EsPermission;
//import cn.cmcc.es.hfy.annotation.EsRole;
//import cn.cmcc.es.hfy.annotation.NoRequestSubmit;
//import cn.cmcc.es.hfy.base.entity.CurrentUser;
//import cn.cmcc.es.hfy.base.entity.Result;
//import cn.cmcc.es.hfy.base.entity.UserRole;
//import cn.cmcc.es.hfy.base.enums.ResultCode;
//import cn.cmcc.es.hfy.redis.RedisUtils;
//import cn.cmcc.es.hfy.utils.HttpUtil;
//
///**
// * 基于角色拦截
// * @author vintone
// */
//@Aspect
//@Component
//public class EsRoleAspect {
//
//	@Autowired
//	private UserService userService;
//
//
//	@Pointcut("@annotation(cn.cmcc.es.hfy.annotation.EsRole)")
//	public void pointCut() {
//
//	}
//
//	@Around("pointCut()")
//	public Object around(ProceedingJoinPoint pjp) throws Throwable {
//		MethodSignature signature = (MethodSignature) pjp.getSignature();
//		Method method = signature.getMethod();
//		EsRole esRole = method.getAnnotation(EsRole.class);
//		if(esRole != null) {
//			// 有加此EsRole注解则需要进行权限认证
//			String roleCode = esRole.code();
//			CurrentUser currentUser = UserUtils.getCurrentUser();
//			List<UserRole> roleDTOs = userService.getRoleByUser(currentUser.getId());
//			if(!hashRole(roleCode, roleDTOs)) {
//				return Result.fail(ResultCode.NO_AUTH);
//			}
//		}
//		return pjp.proceed();
//	}
//
//	/**
//	 * 判断权限是否在集合中
//	 * @param roleCode
//	 * @param roleDTOs
//	 * @return
//	 */
//	public boolean hashRole(String roleCode, List<UserRole> roleDTOs) {
//		for(UserRole roleDTO : roleDTOs) {
//			if(roleDTO.getRoleCode().equalsIgnoreCase(roleCode)) {
//				return true;
//			}
//		}
//		return false;
//	}
//}
